Get Files Name

By Hubert Ronald / Leave a response / May 28, 2018

Many times need a text list with of all files into folder. Python able be help us with it.

Define path and file extension as string variables:

import os, glob

specificPath = "/Users/.../myFolder"      # myFolder is the directory where files are 
fileExtension = "*.png"                   # or "*.jpg", "*.svg" and so on

Load and print file names:

os.chdir(specificPath)
for file in glob.glob(fileExtension):
    print(file)

Sample result:

#-----------------------------
# Printed output in spanish
# because it's my Mother tongue
#-----------------------------
# Run on VS Code
#-----------------------------
'''
[Running] python "/Users/printFiles.py" # path of your script

Captura de pantalla 2018-05-14 a la(s) 1.08.52 a. m..png
Captura de pantalla 2018-05-14 a la(s) 1.35.35 a. m..png
Captura de pantalla 2018-05-14 a la(s) 1.36.13 a. m..png
Captura de pantalla 2018-05-14 a la(s) 12.10.44 a. m..png
Captura de pantalla 2018-05-14 a la(s) 12.31.42 a. m..png
Captura de pantalla 2018-05-14 a la(s) 12.47.04 a. m..png
Captura de pantalla 2018-05-24 a la(s) 6.34.29 p. m..png
Captura de pantalla 2018-05-24 a la(s) 6.56.07 p. m..png
Captura de pantalla 2018-05-24 a la(s) 7.54.21 p. m..png

[Done] exited with code=0 in 0.044 seconds
'''

If need more information about glob module please, check the follow documentation





Hubert Ronald

Hiya. I'm Ronald, an Industrial Engineer from Colombia. Hope you enjoyed my ad-free, bullshit-free site. If you liked it, tell someone about it.

Write a response

Your email address will not be published.

RECENT NEWS

Gradient is a small library which offers a clean, minimalistic but powerful API for gradients on mesh canvas when you use it on Gideros Mobile. This script take colors from uiGradients like inspiration.

More information about before here.

SUBSCRIBE

Get monthly updates and free resources.


CONNECT WITH ME